<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.qifan.alb2b.domain.CountryInfoDomain"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>易能旅游网站</title>
		<%@ include file="/pages/common/common.jsp"%>

		<script type="text/javascript">
		$(function(){	
			$('#gridTable').datagrid({
				title:'订单列表', //标题
				method:'post',
				iconCls:'icon-edit', //图标
				singleSelect:true, //多选
				height:360, //高度
				fitColumns: false, //自动调整各列，用了这个属性，下面各列的宽度值就只是一个比例。
				striped: true, //奇偶行颜色不同
				collapsible:true,//可折叠
				url:"${ctx}/admin/order/query.adm", //数据来源
				sortName: 'orderId', //排序的列
				sortOrder: 'desc', //倒序
				remoteSort: true, //服务器端排序
				idField:'orderId', //主键字段
				queryParams:{}, //查询条件
				pagination:true, //显示分页
				rownumbers:true, //显示行号
				frozenColumns:[[
					{field:'ck',checkbox:true,width:2}, //显示复选框
					{field:'orderId',title:'订单编号',width:150,
						formatter:function(value,row,index){
							return '<a href="javascript:void(0);" onclick="showDetail(\''+row.orderId+'\')"'+row.routeId+'" class="ordera">'+row.orderId+'<a>';
						}	
					}
				]],
				columns:[[
					{field:'day',title:'几天',width:45,sortable:true},
					{field:'night',title:'几夜',width:45},
					{field:'goCityCn',title:'启程城市',width:60},
					{field:'goTime',title:'启程时间',width:80},
					{field:'backTime',title:'返回时间',width:80},
					{field:'groupType',title:'团队类型',width:65,
						formatter:function(value,row,index){
							switch(row.groupType){
								case ${constant.GROUP_TYPE_SIX}:
									return '1-6人团';
									break;
								case ${constant.GROUP_TYPE_SEVEN}:
									return '7-38人团';
									break;
								default:
									return '未知';
									break;
							}
						}	
					},
					{field:'totalCount',title:'总人数',width:45,sortable:true},
					{field:'orderStatus',title:'订单状态',width:65,sortable:true,
						formatter:function(value,row,index){
							switch(row.orderStatus){
								case ${constant.ORDER_STATUS_NOPAY}:
									return '未付款';
									break;
								case ${constant.ORDER_STATUS_PAYED}:
									return '已付款';
									break;
								case ${constant.ORDER_STATUS_OK}:
									return '已确认';
									break;
								case ${constant.ORDER_STATUS_CANCEL}:
									return '已取消';
									break
								default:
									return '未知';
									break;
							}
						}
					},
					{field:'orderTotalAmount',title:'总金额',width:55,sortable:true},
					{field:'createTime',title:'创建时间',width:140,sortable:true},
					{field:'payTime',title:'付款期限',width:140,sortable:true}
				]],
				toolbar:[
					{
						text:'确认收款',
						iconCls:'icon-ok',
						handler:function(){
							updateStatus(${constant.ORDER_STATUS_OK});
						}
					},'-',{
						text:'取消订单',
						iconCls:'icon-close',
						handler:function(){
							updateStatus(${constant.ORDER_STATUS_CANCEL});
						}
					},'-'
				],
				onLoadSuccess:function(){
					$('#gridTable').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题
				}
			});	
		});
		
		/** 更新订单状态 */
		function updateStatus(status){
			var rows = $('#gridTable').datagrid('getSelections');//json：[{},{}]
		
			if(rows.length==0){
				$.messager.alert('提示','请选择你要更新的记录','info');
				return;
			}
			if(rows.length > 1){
				$.messager.alert('提示','只能选择一条记录进行更新','info');
				return;
			}
			var param={
				orderId:rows[0].orderId,	
				orderStatus:status
			};				
			$.post('${ctx}/admin/order/updateStatus.adm',param,function(data){
	        	if(data.success){//操作成功
					$.messager.alert('提示','操作成功','info');
	        		$('#gridTable').datagrid('reload');//刷新数据
				}else{
					$.messager.alert('提示',data.msg,'warning');	
				}
	        });
		}
		
		 /** 表格查询 */
		function searchOrder(){
			var fields =$('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象数据格式如下
		
			var params={};
			$.each( fields, function(i, field){//设置查询参数
				params[field.name] = field.value; 
			});
			$('#gridTable').datagrid('reload',params); //设置好查询参数 reload 一下就可以了
		}
		
		/** 清空查询条件 */
		function clearForm(){
			$('#queryForm').form('clear');
		}
		
		function showDetail(orderId){
			$("#MyPopWindow").window({
	  			title:'订单详细信息',
	  			href:'${ctx}/admin/order/queryOrder.adm?orderId='+orderId,
	  			width:700,
	  			height:530
  			});
		}
	</script>
	<style type="text/css">
		h3{
			display: block;
			border-bottom: 2px solid #92B7D0;
			height: 23px;
			line-height:25px;
			font-size: 15px;
			color: #15428B;
			text-align: left;
			padding-left:25px;
			background-repeat: no-repeat;
			background-position: left center;
		}
	</style>
	</head>
	<body>

		<form id="queryForm" class="qform">
			<table class="qtable" width="100%">
				<tr>
					<td class="qtd">
						订&nbsp;单&nbsp;号：
						<input class="txt" name="orderId" style="width: 100px;">
					</td>
					<td class="qtd">
						订单状态：
						<select class="easyui-combobox" name="orderStatus"
							panelHeight="auto" style="width: 100px;" editable="false">
							<option value="-1">
								请选择
							</option>
							<option value="${constant.ORDER_STATUS_NOPAY}">
								未付款
							</option>
							<option value="${constant.ORDER_STATUS_PAYED}">
								已付款
							</option>
							<option value="${constant.ORDER_STATUS_OK}">
								已确认
							</option>
							<option value="${constant.ORDER_STATUS_CANCEL}">
								已取消
							</option>
						</select>
					</td>
					<td class="qtd">
						团队类型：
						<select class="easyui-combobox" name="groupType"
							panelHeight="auto" style="width: 100px;" editable="false">
							<option value="-1">
								请选择
							</option>
							<option value="${constant.GROUP_TYPE_SIX}">
								1-6人团
							</option>
							<option value="${constant.GROUP_TYPE_SEVEN}">
								7-38人团
							</option>
						</select>
					</td>
					<td class="qtd" align="center">
						<a style="text-decoration: none;" onclick="clearForm();"
							class="easyui-linkbutton" iconCls="icon-no">清空</a>
					</td>
				</tr>
				<tr>
					<td class="qtd" colspan="2">
						创建时间：
						<input class="txt" name="createBeginTime" style="width: 100px;"
							onfocus="WdatePicker();">
							-- <input class="txt" name="createEndTime" style="width: 100px;"
								onfocus="WdatePicker();">
					</td>
					<td class="qtd">
						用&nbsp;户&nbsp;名：
						<input class="txt" name="userName" style="width: 100px;">
					</td>
					<td class="qtd" align="center">
						<a style="text-decoration: none;" onclick="searchOrder();"
							class="easyui-linkbutton" iconCls="icon-search">查询</a>
					</td>
				</tr>
			</table>
		</form>
		<div class="griddiv">
			<table id="gridTable"></table>
		</div>
		<div id="MyPopWindow" modal="true" shadow="false" minimizable="false" cache="false" maximizable="true" collapsible="false" resizable="true" style="margin: 0px;padding: 0px;overflow: auto;"></div>


	</body>

</html>
